<?
require_once('Converter.php');
require_once('ConverterException.php');

abstract class ConverterBase implements Converter {
	abstract protected function toDatatype($string);
	abstract protected function toString($data);

	private $default,$msg;

	public function setDefault($value) { $this->default= $value; return $this; }
	public function getDefault() { return $this->default; }

	public function setErrorMessage($value) { $this->msg= $value; return $this; }
	public function getErrorMessage() { return $this->msg; }

	public function getAsDatatype($string) {
		if (is_null($string)) return $this->getDefault();
		return $this->toDatatype($string);
	}
	public function getAsString($data) {
		if (is_null($data)) {
			if ($this->getDefault()!== null)
				return $this->toString($this->getDefault());
			else
				return null;
		}
		return $this->toString($data);
	}
}